//
//  DocumentationViewController.m
//  TeamInformatization
//
//  Created by bigger on 2019/3/31.
//  Copyright © 2019年 SPIC. All rights reserved.
//

#import "DocumentationViewController.h"
#import "DocumentCollectionViewCell.h"
#import "TitleCollectionReusableView.h"
#import "InformationListViewController.h"

@interface DocumentationViewController () <UICollectionViewDelegate, UICollectionViewDataSource, ChangeContentViewDelegate>

@property (nonatomic, strong) UICollectionView *documentCollectionView;

@end

@implementation DocumentationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self showTitleBarWithTitle:@"文档资料"];
    // UI
    [self loadShowViews];
    
    // Data
    [self requestDocumentData];
}

//
- (void)requestDocumentData
{
    
}

//
- (void)loadShowViews
{
    ChangeContentView *changeView = [[ChangeContentView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight, kScreenWidth, 49 * kScaleWidth) TitleArray:@[@"班组档案", @"上级文件", @"单位文件"]];
    changeView.delegate = self;
    [self.view addSubview:changeView];
    
    // 流水布局
    UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];      //创建流水布局
    flowLayout.itemSize = CGSizeMake(kScreenWidth / 4., 90 * kScaleWidth);      //设置每个格子的尺寸
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumLineSpacing = 0;        //设置每一行之间的间距
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.headerReferenceSize = CGSizeMake(kScreenWidth, 50 * kScaleWidth);
    flowLayout.footerReferenceSize = CGSizeMake(0, 0);
    flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.documentCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, kSafeAreaTopHeight + 49 * kScaleWidth, kScreenWidth, ContentHeight - 49 * kScaleWidth) collectionViewLayout:flowLayout];
    _documentCollectionView.backgroundColor = [UIColor whiteColor];
    _documentCollectionView.delegate = self;
    _documentCollectionView.dataSource = self;
    [_documentCollectionView registerClass:[DocumentCollectionViewCell class] forCellWithReuseIdentifier:@"DocumentCell"];
    [_documentCollectionView registerClass:[TitleCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DocumentType"];
    _documentCollectionView.bounces = NO;
    // 横向滑动
    _documentCollectionView.showsVerticalScrollIndicator = NO;
    _documentCollectionView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:_documentCollectionView];
    
}

#pragma mark - ChangeContentViewDelegate
- (void)getTouchNum:(int)touchNum withChangeContentView:(ChangeContentView *)changeContentView
{
    switch (touchNum) {
        case 0: {
            
            break;
        }
        case 1: {
            
            break;
        }
        case 2: {
            
            break;
        }
            
        default:
            break;
    }
}


#pragma mark - CollectionViewDelegate/DataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 3;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    
    if (kind == UICollectionElementKindSectionHeader){
        
        TitleCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DocumentType" forIndexPath:indexPath];
        
        [headerView setReusableCellTitle:@"基础管理模块"];
        
        return headerView;
        
    } else {
        return nil;
    }
}




- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    DocumentCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DocumentCell" forIndexPath:indexPath];
    
    [cell setShowViewCellWithTitle:@"测试文本" isSingle:!(indexPath.section % 2)];
    
    return cell;
    
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    InformationListViewController *vc = [InformationListViewController new];
    [self.navigationController pushViewController:vc animated:YES];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
